package com.xpert.action.board;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xpert.action.CommandAction;
import com.xpert.beans.Board;
import com.xpert.dao.BoardDao;

public class CountAction implements CommandAction {

  @Override
  public String requestProc(HttpServletRequest request,
  		HttpServletResponse response) throws Throwable {

  	int idx = Integer.parseInt(request.getParameter("idx"));
  	Board board = BoardDao.getInstance().getArticle(idx);
  	String regip = request.getRemoteAddr();
  
  	if(!regip.equals(board.getRegip())) {
  	    int count = board.getCount();
  	    board.setCount(++count);
  	    BoardDao.getInstance().setArticleCount(board);
  	}
  
  	String page = request.getParameter("page");
  	request.setAttribute("url", "view.do?idx=" + idx + "&page=" + page);
  
  	return "redirect.jsp";
  }

}
